﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

namespace ScarEngine
{
    public abstract class Level
    {
        public ContentLoader.TextureLoader TexLoader;
        public ContentLoader.FontLoader FontLoader;
        public Dictionary<string, Texture2D> Textures;
        public Dictionary<string, SpriteFont> Fonts;



        public Level()
        {
            
        }

        public virtual void Init() // Called at the very start
        {
            TexLoader = new ContentLoader.TextureLoader();
            FontLoader = new ContentLoader.FontLoader();
            Textures = new Dictionary<string, Texture2D>();
            Fonts = new Dictionary<string, SpriteFont>();
        }

        public virtual void ContentLoad() // Called when loading content
        {
            
        }

        public virtual void BeginRun() // Called right before the first update runs
        {
            
            
        }

        public virtual void Update(GameTime gameTime) // Called on Update
        {

        }

        public virtual void Dispose()
        {
            Textures = null;
            Fonts = null;
        }


        #region Content Loader

        public void LoadTexture(string FileName)
        {
            LoadTexture(FileName, FileName);
        }

        public void LoadTexture(string Filename, string name)
        {
            if (Textures.ContainsKey(name))
                return;
            Texture2D tex = TexLoader.Load(Filename);
            if (tex != null)
                Textures.Add(name, tex);
        }

        public Texture2D GetTexture(string name)
        {
            if (Textures.ContainsKey(name))
                return Textures[name];
            return Game1.MasterManager.DefaultTex;
        }

        //SPRITEFONTS
        public void LoadFont(string FileName)
        {
            LoadFont(FileName, FileName);
        }

        public void LoadFont(string Filename, string name)
        {
            if (Fonts.ContainsKey(name))
                return;
            SpriteFont font = FontLoader.Load(Filename);
            if (font != null)
                Fonts.Add(name, font);
        }

        public SpriteFont GetFont(string name)
        {
            if (Fonts.ContainsKey(name))
                return Fonts[name];
            return Game1.MasterManager.DefaultFont;
        }

        #endregion



    }

}